﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QuotationService.RealtimeQuotation
{
    internal class MarketInfoConverter:IEntityConverter<Quotation.MarketInfo,MarketInfo>
    {
        public Quotation.MarketInfo Convert(MarketInfo marketInfo)
        {
            return new Quotation.MarketInfo()
            {
                MarketTime = marketInfo.MarketTime,
                TradeDay = Quotation.Date.FromYMMDD(marketInfo.TradeDay),
                UpdateTime = Quotation.Time.FromHMMss(marketInfo.UpdateTime),
                Status = (Quotation.MarketStatus)marketInfo.Status,
                TradingSession = Quotation.TimeRangeCollection.Parse(marketInfo.TradeTimeZone),
                ChartTimeSlots = Quotation.TimeRangeCollection.Parse(marketInfo.ChartTimeSlots)
            };
        }

        public MarketInfo Convert(Quotation.MarketInfo marketInfo)
        {
            var rtn = new MarketInfo()
            {
                MarketTime = marketInfo.MarketTime,
                TradeDay = marketInfo.TradeDay.ToYMMDD(),
                UpdateTime = marketInfo.UpdateTime.ToHMMss(),
                Status = (MarketStatus)marketInfo.Status
            };
            if (marketInfo.TradingSession != null)
                rtn.TradeTimeZone = marketInfo.TradingSession.ToString();
            if (marketInfo.ChartTimeSlots != null)
                rtn.ChartTimeSlots = marketInfo.ChartTimeSlots.ToString();
            return rtn;
        }
    }
}
